package cn.edu.cjw.APMFP.BOMTable.Service;

import java.util.ArrayList;

import cn.edu.cjw.APMFP.BOMTable.DAO.BOMTableDAO;
import cn.edu.cjw.APMFP.BOMTable.DAO.BOMTableDAOImpl;
import cn.edu.cjw.APMFP.BOMTable.pojo.BOMTable;

public class BTServiceImpl implements BTService {

	BOMTableDAO bDao = new BOMTableDAOImpl();

	public boolean addBOM(String BId,String BName,String Btype,String unit) throws Exception {

		boolean flag = false;

		if (bDao.searchById(BId).judge()) {
			return flag;
		} else {
			BOMTable bomTable = new BOMTable(BId, BName, Btype, unit);
			flag = bDao.addAndUpdateBOM(bomTable);
		}

		return flag;
	}

	public boolean updateBOMName(BOMTable bomTable, String name) throws Exception {

		bomTable.setBName(name);
		return bDao.addAndUpdateBOM(bomTable);

	}

	public boolean updateBOMType(BOMTable bomTable, String type) throws Exception {

		bomTable.setBtype(type);

		return bDao.addAndUpdateBOM(bomTable);
	}

	public boolean UpdateBOMUnit(BOMTable bomTable, String unit) throws Exception {
		bomTable.setUnit(unit);
		return bDao.addAndUpdateBOM(bomTable);
	}
	
	public boolean updateBOM(BOMTable bomTable, String name, String type, String unit) throws Exception {
		bomTable.setBName(name);
		bomTable.setBtype(type);
		bomTable.setUnit(unit);
		return bDao.addAndUpdateBOM(bomTable);

	}

	public boolean removeBOM(BOMTable bomTable) throws Exception {

		return bDao.removeBOM(bomTable);
		
	}

	public BOMTable searchById(String id) throws Exception {
		return bDao.searchById(id);
	}

	public ArrayList<BOMTable> searchByName(String name) throws Exception {
		return bDao.searchByName(name);
	}

	public ArrayList<BOMTable> searchByType(String type) throws Exception {
		return bDao.searchByType(type);
	}

	public ArrayList<BOMTable> searchByUnit(String unit) throws Exception {
		return bDao.searchByUnit(unit);
	}

	public ArrayList<BOMTable> showAll() throws Exception {
		return bDao.showAll();
	}

	

}
